#include <iostream>
typedef long long ll;
using namespace std;

ll gcd(ll x, ll y){
	ll n=-1;
	do{
		n=y%x;
		y=x;
		x=n;
	}while(n!=0);
	return y;
}

int main()
{
	ll a=-1,b=-1,x=-1,y=-1;
	cin>>a>>b>>x>>y;
	ll g=gcd(x,y);
	x/=g, y/=g;
	cout<<min(a/x,b/y)<<endl;
	
	return 0;
}
